<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function add(a, b, c) {
            return a + b + c
        }
        console.log(add(1,2,3))
        console.log(add(1,2)) //不传c，c为undefined。结果NaN
        
        //1.函数默认值
        function add2(a, b, c=10) { //指定c的默认值，默认值一般放最后一个（最后几个）
            return a + b + c
        }
        console.log(add2(1,2,3))
        console.log(add2(1,2)) //不传c，c为默认值10

        //2.与解构赋值结合
        function connect({host='127.0.0.1', port, user, password}) {
            console.log(host, port, user, password)
        }
        connect({
            host: 'localhost',
            port: 3306,
            user: 'root',
            password: '123456',
        })
        //不传host，用默认值
        connect({
            port: 3306,
            user: 'root',
            password: '123456',
        })
    </script>
</body>
</html>